/*
  学习目标：setState第二种写法
*/

import React, { Component } from 'react';

export default class App extends Component {
  state = {
    count: 0,
  };

  handleClick = () => {
    // 语法: setState((旧的state) => 新的state对象)
    // 💥 箭头函数的写法, 依然会造成合并的效果
    // 合并: 根据上一次的计算结果, 计算下一次的值
    // 还是异步的
    this.setState((preState) => {
      return {
        count: preState.count + 1,
      };
    });
    this.setState((preState) => {
      return {
        count: preState.count + 2,
      };
    });
    this.setState((preState) => {
      return {
        count: preState.count + 3,
      };
    });

    console.log('this.sate.count  ----->  ', this.state.count);
  };

  render() {
    console.log('render  ----->  ');
    const { count } = this.state;
    return (
      <div>
        <h1>{count}</h1>
        <button onClick={this.handleClick}>点我更细</button>
      </div>
    );
  }
}
